package com.atguigu.demo0428.customer.controller;


import com.atguigu.demo0428.customer.bean.Customer;
import com.atguigu.demo0428.customer.service.CustomerService;
import com.atguigu.demo0428.customer.service.impl.CustomerServiceImpl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class CustomerController {

    @Autowired
    CustomerService customerService;


    @RequestMapping("/hello")
    public  String hello(@RequestParam("customerName") String name ,@RequestParam(value = "customerAge",required = false ,defaultValue = "0")  Integer age){
         return  "hello world:"+name+"--"+age;
    }

    @GetMapping("/customer/{id}")
    public String  getCustomer(@PathVariable("id") String id){
        return  "customer:"+id;
    }
    @RequestMapping("/customers")
    public List<Customer> getCustomers(@RequestParam("customerName") String name){
      //  List<Customer> customerList = customerService.getCustomerListByName(name);
        List<Customer> customerList1 = customerService.list(new QueryWrapper<Customer>().eq("customer_name", name));
        return customerList1;

    }

    @PostMapping("/customer")
    public String  saveCustomer(@RequestBody  Customer customer){
        System.out.println( "save:"+customer);
         customerService.saveCustomer(customer);
      //  customerService.saveOrUpdate(customer);
        return "success";
    }
}
